package com.zzyl.nursing.controller.member;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.nursing.vo.member.CountByTimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Long> getCancelledReservationCount() {
        return R.ok(reservationService.getCancelledReservationCount());
    }

    /**
     * 查询每个时间段剩余预约次数
     */
    @GetMapping("/countByTime")
    private R<List<CountByTimeVo>> getCountByTime(@RequestParam Long time){
        return R.ok(reservationService.getCountByTime(time));
    }
    /**
     * 新增预约信息
     */
    @PostMapping
    public AjaxResult addReservation(@RequestBody Reservation reservation)
    {
        reservationService.addReservation(reservation);
        return success();
    }

    /**
     * 分页查询预约
     */
    @GetMapping("/page")
    public R<TableDataInfo<List<Reservation>>> page(@RequestParam(required = false) Integer status) {
        startPage();
        return R.ok(getDataTable(reservationService.getReservationList(status)));
    }

    /**
     * 取消预约
     */
    @PutMapping("/{id}/cancel")
    public AjaxResult cancelReservation(@PathVariable("id") Long id){
        reservationService.cancelReservation(id);
        return success();
    }
}